CC=mpicc
CXX=mpicxx
LD=mpiCC
FC=mpif77

CFLAGS =    -g -Wall -O3 -I../../
FFLAGS =    
LDFLAGS =	-lgfortran -lz -Llib -lst -L../../crf_sequence/lib -lcrf

all: bin/train_detect bin/st_crf bin/st_decode

bin/train_detect: build/train_detect.o lib/libst.a
ifeq ($(MACH),solaris2.9)
	$(CXX) $^ build/getopt.o -o $@ $(LDFLAGS) -Llib -lst
else
	$(CXX) $^ -o $@ $(LDFLAGS) -Llib -lst
endif

bin/st_crf: build/st_crf.o build/st_cmdline.o \
	../../crf_sequence/lib/libcrf.a lib/libst.a
ifeq ($(MACH),solaris2.9)
	$(CXX) $^ build/getopt.o -o $@ $(LDFLAGS) -Llib -lst
else
	$(CXX) $^ -o $@ $(LDFLAGS) -Llib -lst
endif

bin/st_decode: build/st_decode.o build/st_cmdline.o build/st_wrapper.o \
	build/st_classifier.o ../../crf_sequence/lib/libcrf.a lib/libst.a
ifeq ($(MACH),solaris2.9)
	$(CXX) $^ build/getopt.o -o $@ $(LDFLAGS) -Llib -lst
else
	$(CXX) $^ -o $@ $(LDFLAGS) -Llib -lst
endif

lib/libst.a: build/sequence_corpus_reader.o \
	build/cmdline.o build/gzstream.o build/detect_nodes.o \
	build/detect_cliques.o
	ar rc $@ $^
	ranlib $@

build/%.o: %.cpp
	${CXX} $(CFLAGS) -c $< -o $@

build/%.o: %.c
	${CC} $(CFLAGS) -c $< -o $@

build/%.o: %.f
	$(G77) -c $< -o $@

getopt: getopt.h getopt.c getopt1.c
	$(CC) $(CFLAGS) -c getopt.c getopt1.c -o build/getopt.o

cmdline: cmdline.ggo st_crf.ggo
	gengetopt --conf-parser -i st_crf.ggo -F st_cmdline
	gengetopt -a "Parameters" -f align_parser --conf-parser -i cmdline.ggo -F cmdline
	cat cmdline.c | sed -e 's/cmd_line_list/align_cmd_line_list/g' > tmp
	mv tmp cmdline.c
	cat cmdline.c | sed -e 's/my_argv/align_my_argv/g' > tmp
	mv tmp cmdline.c

depend:
	makedepend -- $(CFLAGS) -- -p "build/" -Y *.cpp *.c

clean:
	rm -f build/*.o

clobber: clean
	rm -f bin/train_detect
	rm -f lib/libalign.a
# DO NOT DELETE

build/detect_cliques.o: detect_cliques.h cmdline.h detect_nodes.h
build/detect_cliques.o: sequence_corpus_reader.h gzstream.h
build/detect_nodes.o: detect_nodes.h cmdline.h sequence_corpus_reader.h
build/detect_nodes.o: gzstream.h
build/gzstream.o: gzstream.h
build/sequence_corpus_reader.o: sequence_corpus_reader.h gzstream.h cmdline.h
build/st_classifier.o: st_classifier.h ../../crf_sequence/crf_classifier.h
build/st_classifier.o: ../../crf_sequence/param.h
build/st_classifier.o: ../../crf_sequence/sparse_array.h
build/st_classifier.o: ../../crf_sequence/data.h
build/st_classifier.o: ../../crf_sequence/sparse_matrix.h
build/st_classifier.o: ../../crf_sequence/param.h ../../crf_sequence/data.h
build/st_classifier.o: ../../crf_sequence/util.h ../../crf_sequence/bp.h
build/st_classifier.o: gzstream.h st_wrapper.h detect_cliques.h cmdline.h
build/st_classifier.o: detect_nodes.h sequence_corpus_reader.h
build/st_crf.o: ../../crf_sequence/crf_learn.h ../../crf_sequence/param.h
build/st_crf.o: ../../crf_sequence/data.h ../../crf_sequence/sparse_array.h
build/st_crf.o: ../../crf_sequence/sparse_matrix.h
build/st_crf.o: ../../crf_sequence/crf_minable.h ../../crf_sequence/lbfgs.h
build/st_crf.o: ../../crf_sequence/util.h ../../crf_sequence/param.h
build/st_crf.o: ../../crf_sequence/sparse_array.h ../../crf_sequence/util.h
build/st_crf.o: ../../crf_sequence/data.h st_cmdline.h st_classifier.h
build/st_crf.o: ../../crf_sequence/crf_classifier.h detect_cliques.h
build/st_crf.o: cmdline.h detect_nodes.h sequence_corpus_reader.h gzstream.h
build/st_decode.o: ../../crf_sequence/crf_learn.h ../../crf_sequence/param.h
build/st_decode.o: ../../crf_sequence/data.h
build/st_decode.o: ../../crf_sequence/sparse_array.h
build/st_decode.o: ../../crf_sequence/sparse_matrix.h
build/st_decode.o: ../../crf_sequence/crf_minable.h
build/st_decode.o: ../../crf_sequence/lbfgs.h ../../crf_sequence/util.h
build/st_decode.o: ../../crf_sequence/param.h
build/st_decode.o: ../../crf_sequence/sparse_array.h
build/st_decode.o: ../../crf_sequence/util.h ../../crf_sequence/data.h
build/st_decode.o: st_cmdline.h st_classifier.h
build/st_decode.o: ../../crf_sequence/crf_classifier.h detect_cliques.h
build/st_decode.o: cmdline.h detect_nodes.h sequence_corpus_reader.h
build/st_decode.o: gzstream.h
build/st_wrapper.o: ../../crf_sequence/data.h st_wrapper.h detect_cliques.h
build/st_wrapper.o: cmdline.h detect_nodes.h sequence_corpus_reader.h
build/st_wrapper.o: gzstream.h
build/train_detect.o: cmdline.h detect_cliques.h detect_nodes.h
build/train_detect.o: sequence_corpus_reader.h gzstream.h
build/cmdline.o: getopt.h cmdline.h
build/getopt.o: getopt.h
build/getopt1.o: getopt.h
build/st_cmdline.o: getopt.h st_cmdline.h
